#ifndef MAINWIDGET_H
#define MAINWIDGET_H

#include <QWidget>
#include <QLabel>
#include <QLineEdit>
#include <QTextEdit>
#include <QPushButton>
#include <QProgressBar>
#include <QtNetwork/QNetworkAccessManager>
#include <QNetworkReply>
#include <QUrl>
#include <QFile>
#include <QTime>

class MainWidget : public QWidget
{
    Q_OBJECT

public:
    MainWidget(QWidget *parent = nullptr);
    ~MainWidget();

private:
    void createWidget();
    void createNetworkManager();

    void startRequest(QUrl url);

private slots:
    void on_btnDownLoad_Clicked();
    void on_btnCancel_Clicked();

    void on_btnGet_Clicked();

    void httpReadyRead();
    void httpFinished();
    void updateProgress(qint64 bytesReceived, qint64 bytesTotal);

    void requestFinished(QNetworkReply* reply);

private:
    QLabel *labAddress;
    QLineEdit *lineEditAddr;
    QTextEdit *textEdit;
    QProgressBar *progress;
    QPushButton *btnDownLoad;
    QPushButton *btnCancel;

    QPushButton *m_btGetRequest;

    QNetworkAccessManager *manager;

    QNetworkReply *reply;
    QUrl url;
    QFile *file;

    QTime time;

};

#endif // MAINWIDGET_H
